package psrc.logic.pages.cliente;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import psrc.logic.pages.base.ControllerBase;
import psrc.logic.util.beans.ClienteBean;

public class SendClienteRemoveController extends ControllerBase{

	private static final long serialVersionUID = 1L;
	String[] clienteCheckbox;

	@Override
	public String executeController() throws Exception {
		ClienteModel model = new ClienteModel();
		List<ClienteBean> todosClientes = model.getClientesList();
		List<ClienteBean> clientesParaRemover = new ArrayList<ClienteBean>();
		List<String> idsParaRemover = Arrays.asList(getClienteCheckbox());

		for (ClienteBean prod : todosClientes) {
			if (idsParaRemover.contains(prod.getIdCliente())) {
				clientesParaRemover.add(prod);
			}
		}
		try{
			if (model.removeCliente(clientesParaRemover)) {
				return SUCCESS;
			}
		} catch (Exception e) {
			addActionError(getText("error.constraint"));
		}
		return ERROR;
	}

	/**
	 * @return the clienteCheckbox
	 */
	public String[] getClienteCheckbox() {
		return clienteCheckbox;
	}

	/**
	 * @param clienteCheckbox
	 *            the clienteCheckbox to set
	 */
	public void setClienteCheckbox(String[] clienteCheckbox) {
		this.clienteCheckbox = clienteCheckbox;
	}


}
